package sketch.skeleton;

import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.Name;

import sketch.util.Checker;

public class GeneratorSourceCode extends SkeletonElement {
	
	public final int index;
	
	public final Expression expr;
	
	public final String receiverObj;
	
	private String outputString = null;
	
	public GeneratorSourceCode(int index, Expression expr) {
		Checker.checkTrue(index > -1, "The index should >= 0.");
		Checker.checkNull(expr, "The expression could not be null.");
		this.index = index;
		this.expr = expr;
		this.receiverObj = expr.toString();
	}
	
	//XXX many kinds of expression
	public String getReceiverString() {
		String receiverExpr = expr.toString();
		if(this.expr instanceof Name) {
		    return receiverExpr;
		} else {
			return "(" + receiverExpr + ")";
		}
	}
	
	public void setGeneratedString(String outputString) {
		Checker.checkNull(outputString, "The outputString argument could not be null.");
		this.outputString = outputString;
	}

	@Override
	public String toCodeString() {
		//throw new UnsupportedOperationException("Method toCodeString() is not supported in GeneratorSourceCode!");
		return outputString;// + "  " + this.expr.toString();
	}

}
